package com.example.night.data.InfluencerCoins;

import com.example.night.data.InfluencerCoins.WithdrawRecord;
import com.example.night.data.InfluencerCoins.WithdrawRecord.WithdrawStatus;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

@Repository
public interface WithdrawRecordRepository extends JpaRepository<WithdrawRecord, Long> {

    // 根据抖音 ID 查询所有提现记录
    List<WithdrawRecord> findByPromoteId(String promoteId);

    // 根据抖音名查询所有提现记录
    List<WithdrawRecord> findByPromoteName(String promoteName);


    List<WithdrawRecord> findByApplyTimeBetween(LocalDateTime startTime, LocalDateTime endTime);

    List<WithdrawRecord> findByCompleteTimeBetween(LocalDateTime startTime, LocalDateTime endTime);


    // 根据提现状态查询提现记录
    List<WithdrawRecord> findByStatus(WithdrawStatus status);

    // 根据抖音 ID 和提现状态查询记录
    List<WithdrawRecord> findByPromoteIdAndStatus(String promoteId, WithdrawStatus status);


    @Modifying
    @Transactional
    @Query("UPDATE WithdrawRecord w SET w.status = :status WHERE w.promoteId = :promoteId")
    int updateWithdrawStatusByPromoteId(@Param("promoteId") String promoteId, @Param("status") WithdrawRecord.WithdrawStatus status);
}
